package com.pfzy.ui

import android.app.Activity
import android.app.Application
import android.os.Bundle

class AppLifecycleCallback : Application.ActivityLifecycleCallbacks {
    companion object {
        val TAG = "AppLifecycleCallback"
    }

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
        //获取Activity弱引用
        ForegroundActivityManager.getInstance().setCurrentActivity(activity)
    }

    override fun onActivityStarted(activity: Activity) {
    }

    override fun onActivityResumed(activity: Activity) {
        // 获取Activity弱引用
        ForegroundActivityManager.getInstance().setCurrentActivity(activity)
        // 设置当前Active状态为true
        ForegroundActivityManager.getInstance().setActive(true)
    }

    override fun onActivityPaused(activity: Activity) {
        // 设置当前Active状态为false
        ForegroundActivityManager.getInstance().setActive(false)
    }

    override fun onActivityStopped(activity: Activity) {
    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
    }

    override fun onActivityDestroyed(activity: Activity) {
    }
}
